﻿@using Trirand.Web.Mvc;

@model  IEnumerable<Se.Framework.Web.Mvc.GenericCrud.GenericCrudViewModel>
@{
    ViewBag.Title = "Multiple";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/trirand/ui.jqgrid.css")" rel="stylesheet" />
<script type="text/javascript" src="@Url.Content("~/Scripts/trirand/jquery.jqGrid.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/trirand/jquery.jqGrid.locale-es.js")"></script>
<script type="text/ecmascript">
    function validateDate(value, colname) {
        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

        var matchArray = value.match(datePat); // is the format ok?
        if (matchArray == null) {
            return [false, "La fecha no está en el formato correcto."];
        }

        var day = matchArray[1]; // parse date into variables
        var month = matchArray[3];
        var year = matchArray[4];

        if (month < 1 || month > 12) {
            return [false, "El mes debe ser entre 1 y 12"];
        }

        if (day < 1 || day > 31) {
            return [false, "El día debe ser entre 1 y 31"];
        }

        if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) {
            return [false, "El mes " + month + " no tiene 31 días"];
        }

        if (month == 2) { // check for february 29th
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
            if (day > 29 || (day == 29 && !isleap)) {
                return [false, "Febrero en " + year + " no tiene " + 29 + " días"];
            }
        }

        return [true, ""];
    }

    function afterSubmit(data_from_server, array_data) {
        var result = $.parseJSON(data_from_server.responseText);
        if (result.Valid == false) {
            var div = $("<div class='hidden'>" + result.Message + "</div>");
            $("#errorHolder").append(div);
            div.show(400).delay(5000).hide(1000, function () {
                div.remove();
            });
        }

    }

    function executionOk(data) {
        alert("Hecho!");
    }

    function executionNotOk(data) {
        alert("Ocurrió un error!");
    }    

</script>
@section featured {
    <section  class="featured hidden" slide-down="slow">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>Multiple</h1>
            </hgroup>
        </div>
    </section>
}
@foreach (var item in Model)
{
    <div>
        @Html.Partial("EntityGrid", item)
    </div>
}

@Html.Trirand().JQDatePicker(new JQDatePicker
    {
        DisplayMode = DatePickerDisplayMode.ControlEditor,
        ShowOn = ShowOn.Focus,
        DateFormat = "dd/MM/yyyy"
    }, "CrudDatePicker") <span id="errorHolder" class="error"></span>
